package com.assess.web.controller;

import com.assess.web.model.Phases;
import com.assess.web.service.PhasesService;
import com.assess.web.util.RespParam;
import javafx.scene.effect.Bloom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by dimingming on 2018/12/8.
 */
@Controller
@RequestMapping("/phases")
public class PhasesController extends BaseController {

    @Autowired
    private PhasesService phasesService;

    @ResponseBody
    @RequestMapping("list")
    public RespParam<List<Phases>> listPhases(@RequestParam(name = "parentId", required = false) Integer parentId) {

        return success(phasesService.list(parentId));
    }

    /**
     * 删除阶段设置（或业态）
     *
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("delete")
    public RespParam<Boolean> delete(@RequestParam(name = "id") Integer id) {
        phasesService.delete(id);
        return success(true);
    }

    /**
     * 添加阶段设置（或业态）
     *
     * @param name
     * @param parentId
     * @return
     */
    @ResponseBody
    @RequestMapping("save")
    public RespParam<Integer> save(@RequestParam("name") String name,
                                   @RequestParam(name = "parentId", required = false) Integer parentId) {
        return success(phasesService.save(parentId, name.trim()));
    }
}
